package com.leetcode.August;

/**
 * @Description: 204. 计数质数
 * @Author: Mr.Fxy
 * @CreateTime: 2024-09-10 19:49
 */
public class LC204计数质数 {
    public int countPrimes(int n) {
        int ans = 0;
        for (int i = 2; i < n; i++) {
            ans += isPrime(i) ? 1 : 0;
        }
        return ans;
    }

    private boolean isPrime(int i) {
        for (int j = 2; j *j<i ; j++) {
            if (i % j == 0)return false;
        }
        return true;
    }
}
